package com.zy.view.study;

import android.content.Context;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import android.util.AttributeSet;
import android.view.MotionEvent;
import android.widget.FrameLayout;

import com.zy.zlog.ZLog;

public class DiyFrameLayoutB extends FrameLayout {

    private static final String TAG = "DiyFrameLayoutB";

    public DiyFrameLayoutB(@NonNull Context context) {
        super(context);
    }

    public DiyFrameLayoutB(@NonNull Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    public DiyFrameLayoutB(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    public DiyFrameLayoutB(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr, int defStyleRes) {
        super(context, attrs, defStyleAttr, defStyleRes);
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        ZLog.d(TAG, "widthMeasureSpec:" + MeasureSpec.toString(widthMeasureSpec) + " heightMeasureSpec:" + MeasureSpec.toString(heightMeasureSpec));
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
    }

    @Override
    protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
        ZLog.d(TAG, "onLayout s 测量宽高:[" + getMeasuredWidth() + "," + getMeasuredHeight() + "] 实际宽高[" + getWidth() + "," + getHeight() + "] " + "[" + left + "," + top + "," + right + "," + bottom + "]");
        //ZLog.d(TAG, "onLayout s 测量宽高:[" + getMeasuredWidth() + "," + getMeasuredHeight() + "] 实际宽高[" + getWidth() + "," + getHeight() + "]");
        //ZLog.d(TAG, "onLayout s :[" + left + "," + top + "," + right + "," + bottom + "]");
        super.onLayout(changed, left, top, right, bottom);
        //ZLog.d(TAG, "onLayout e 测量宽高:[" + getMeasuredWidth() + "," + getMeasuredHeight() + "] 实际宽高[" + getWidth() + "," + getHeight() + "]");
    }

    @Override
    public boolean dispatchTouchEvent(MotionEvent ev) {
        boolean handle;
        if (onInterceptTouchEvent(ev)) {
            handle = onTouchEvent(ev);
        } else {
            handle = getChildAt(0).dispatchTouchEvent(ev);
        }
        return handle;
    }

    @Override
    public boolean onInterceptTouchEvent(MotionEvent ev) {
        return super.onInterceptTouchEvent(ev);
    }

    @Override
    public boolean onTouchEvent(MotionEvent event) {
        return super.onTouchEvent(event);
    }
}
